<?php
$page_title = 'eTAT';
require_once 'controller.php';

if($params->c != '') {
	$course = $instructor->getCourse($params->c);
	$groups = $course->getAllGroups();
} else {
	redirect('home.php');
}

if(isset($_POST['add_group_submit'])) {
	unset($_SESSION['add_project']);
	$_SESSION['add_project']->course = $course->id;
	$_SESSION['add_project']->step = 0;
	redirect('addgroup.php');
}

require_once 'header.php';
?>
<h1><?php print anchor('/home.php','Home').' > '.$course->title ?></h1>

<div id='parser-update-data' class='invisible'>
	<?php 
	$course = $instructor->getCourse($params->c);
	$all_groups = $course->getAllGroups();
	if($all_groups) {
		$ids = array();
		foreach($all_groups as $ag) {
			$ids[] = $ag->id;
		}
		print json_encode($ids);
	}
	?>
</div>
<h3>Groups:</h3>
<?php 
if(isset($groups)) {
	foreach($groups as $g) {
		print "<div id='$g->id-details'>";
		print "<a href='group.php?g=$g->id'>$g->name</a><ul class='indent'>";
		print "<li>SVN Commits: {$g->getSVNCount()}</li>
			<li>Wiki Updates: {$g->getWikiCount()}</li>
			<li>Forum Posts: {$g->getForumCount()}</li>
			<li>Files: {$g->getFileCount()}</li>
			<li>Issue Tracker Updates: {$g->getIssueCount()}</li>";
		print '</ul></div>';
	}
} else {
?>
<p>Looks like you haven't added any groups for monitoring, yet.</p>
<p>Let's get started by pressing the <b>Add Group</b> button below:</p>
<?php 
}
$form = new Form('add_group_form','post');
$form->button('add_group_submit','Add Group',array('type'=>'submit'));
print $form->build();
?>

<div class='clear'></div>
<?php require_once 'footer.php'; ?>